#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Line{
    LL l,r;
}lines[maxn];
LL ans[maxn];
bool cmp(Line A,Line B){
    return (A.r-A.l-1)<(B.r-B.l-1);
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m;cin>>n>>m;
  for(LL i=1;i<=m;i++){
     LL l,r;cin>>l>>r;
     lines[i].l=l;lines[i].r=r;
  }
  sort(lines+1,lines+1+m,cmp);
  LL ans=lines[1].r-lines[1].l+1;
  cout<<ans<<"\n";
  for(LL i=0;i<n;i++){
    cout<<(i%ans)<<" ";
  }
  cout<<"\n";
return 0;
}
